<template>
  <!-- Content Wrapper. Contains page content -->
  <div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <section class="content-header">
      <h1>
        用户管理
        <small>管理您仓库的员工</small>
      </h1>
      <ol class="breadcrumb">
        <li><a href="#"><i class="fa fa-user"></i> 用户管理</a></li>
        <li class="active">添加用户</li>
      </ol>
    </section>

    <!-- Main content -->
    <section class="content">
      <div class="row">
        <div class="col-xs-12">
          <div class="box box-primary">
            <div class="box-header with-border">
              <h3 class="box-title">添加用户</h3>
            </div>
            <!-- /.box-header -->
            <div class="box-body">
              <form role="form">
                <!-- text input -->
                <div class="form-group">
                  <label for="username">用户名</label>
                  <input id="username" v-model="username" class="form-control" placeholder="请输入用户名" type="text">
                </div>
                <div class="form-group">
                  <label for="type">类型</label>
                  <select id="type" v-model="type" class="form-control js-example-basic-single">
                    <option value="admin">管理员</option>
                    <option value="worker">普通员工</option>
                  </select>
                </div>
                <div class="form-group">
                  <label for="password">密码</label>
                  <input id="password" v-model="password" class="form-control" placeholder="请输入密码" type="password">
                </div>
                <div class="form-group">
                  <label for="confirmPassword">确认密码</label>
                  <input id="confirmPassword" v-model="password1" class="form-control" placeholder="请再次输入相同的密码"
                         type="password">
                </div>
                <div>
                  <p id="message" class="alert alert-danger hidden">message</p>
                </div>
              </form>
            </div>
            <div class="box-footer">
              <button class="btn btn-primary" @click="add">点击提交</button>
            </div>
            <!-- /.box-body -->
          </div>
        </div>
        <!-- /.col -->
      </div>
      <!-- /.row -->
    </section>
    <!-- /.content -->
  </div>
  <!-- /.content-wrapper -->
</template>

<script>
export default {
  name: "AddUser",
  data() {
    return {
      username: "",
      password: "",
      password1: "",
      type: ""
    }
  },
  methods: {
    add() {
      if (this.username === "" || this.password === "" || this.password1 === "") {
        this.$message.warning("用户数据不完整");
      } else {
        if (this.password1 === this.password) {
          this.GLOBAL.appData.userList.push({
            "id": this.GLOBAL.appData.userList.length + 1,
            "username": this.username,
            "password": this.password,
            "type": this.type,
          })
          this.$router.push("/main/userData");
        } else {
          this.$message.warning("两次密码输入不一致");
        }
      }
    }
  }
}
</script>

<style scoped>

</style>